<?php

class data_searchinfo extends data_base
{
    public function __construct()
    {
        parent::__construct();
        $this->_table = 'search_info';
    }
	
	public function get_search_info()
	{
		$sql = "SELECT si.id, si.search_name, si.search_name, si.city, spi.pic_url, spi.pic_height, spi.pic_width, spi.last_click_date
				FROM search_info AS si LEFT JOIN search_pic_info AS spi ON si.search_pic_id = spi.id 
				WHERE is_publish = 1 AND si.is_del = 0 ORDER BY si.station ASC, spi.last_click_date DESC";
		return $this->_db->fetchAll( $sql );
	}
	
	public function get_search_info_by_id($id)
	{
		$sql = "SELECT si.*, spi.pic_url FROM search_info AS si LEFT JOIN search_pic_info AS spi ON si.search_pic_id = spi.id
				WHERE si.id = $id AND si.is_del = 0";
		return $this->_db->fetchRow( $sql );
	}
	
	function update_station($id, $stations)
    {
        if ( !is_numeric( $id ) ) return false;		
		$sql = "UPDATE $this->_table SET `station` = station - $stations  WHERE  id = '$id'";
		
        return $this->_db->exec_sql( $sql );
    }
}
?>
